<?php

namespace app\admin\controller\order;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Db;

/**
 * @ControllerAnnotation(title="用户打赏列表")
 */
class PriceDifference extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\OrderPriceDifference();
        
    }

    
    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $count = $this->model
                ->where($where)
                ->where("status",1)
                ->count();
            $list = $this->model
                ->where($where)
                ->where("status",1)
                ->page($page, $limit)
                ->order($this->sort)
                ->select();
                foreach ($list as $k => $v){
                    //用户
                    if(!empty($v['uid'])){
                        $user = Db::name('user')->where('id',$v['uid'])->field('nickname')->find();
                    }else{
                        $user['nickname'] = "";
                    }
                    //达人
                    if(!empty($v['service_technician_id'])){
                        $service_technician = Db::name('service_technician')->where('id',$v['service_technician_id'])->field('service_name')->find();
                    }else{
                        $service_technician['service_name'] = "";
                    }
                    //支付时间
                    if(!empty($v['pay_time'])){
                        $v['pay_time'] = date("Y-m-d H:i:s",$v["pay_time"]);
                    }else{
                        $v['pay_time'] = "";
                    }
 
                    $v['nickname'] = $user['nickname'];
                    $v['service_name'] = $service_technician['service_name'];
                    $list[$k] = $v;
                }
          
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }
 

    
}